package com.wjs.CarolSecKill.controller;

import com.wjs.CarolSecKill.pojo.User;
import com.wjs.CarolSecKill.service.IUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户表
 *
 * @author 作者
 * @date 2022-09-03
 */
@RestController
@RequestMapping("/user")
@Api(value = "用户表",tags = "用户表")
public class UserController {

    @Autowired
    private IUserService userService;

    @ResponseBody
    @RequestMapping("/info")
    public Object test(@CookieValue("userTicket")String ticket, HttpServletRequest request,
                       HttpServletResponse response){
        if(StringUtils.isEmpty(ticket)){
            return "无cookie";
        }
        User user = userService.getUserByTicket(ticket, request, response);
        return user;
    }
}
